package com.yunche.yunchebusiness.ui.activity.accountbook

import android.annotation.SuppressLint
import android.app.Activity
import com.bumptech.glide.Glide
import com.yunche.yunchebusiness.R
import com.yunche.yunchebusiness.base.BaseActivity
import com.yunche.yunchebusiness.base.rx.SchedulerUtils
import com.yunche.yunchebusiness.common.CommonDialog
import com.yunche.yunchebusiness.common.Constant
import com.yunche.yunchebusiness.entity.AccountBookEntity
import com.yunche.yunchebusiness.network.RetrofitManager
import com.yunche.yunchebusiness.network.exception.ExceptionHandle
import com.yunche.yunchebusiness.utils.ToastyUtils
import kotlinx.android.synthetic.main.activity_order_detail.*


class OrderDetailActivity : BaseActivity() {

    var orderId:String = ""

    override fun setLayout(): Int = R.layout.activity_order_detail

    override fun initView() {
        orderId = intent.getStringExtra("orderId");
    }

    override fun initData() {
        getOrderDetail();
    }

    override fun initEvent() {

    }


    @SuppressLint("CheckResult")
    private fun getOrderDetail() {
        CommonDialog.showLoading(mContext!!, Constant.Loading)
        RetrofitManager.service.getOrderDetail(orderId)
            .compose(SchedulerUtils.ioToMain())
            .subscribe({
                CommonDialog.cancle()
                setData(it.datas!!)
            }, {
                CommonDialog.cancle()
                ToastyUtils.showError(ExceptionHandle.handleException(it))
            })
    }

    private fun setData(detail:AccountBookEntity){
        Glide.with(mContext as Activity).load(detail.carIcon).into(iv_brand_cover)
        tv_brand_title.text = detail.carBrand+detail.carModel+detail.carDetail
        tv_price.text = detail.carPrice.toString()+"万"
        tv_canal.text = detail.partnerName
        tv_salesman.text = detail.creditOperatorName
        tv_customer.text = detail.name
        tv_order_date.text = detail.createDate
        tv_order_status.text = if (detail.orderStatus==1) "贷款办理中" else if (detail.orderStatus==2) "贷款办理成功" else "贷款办理失败"
        tv_put_date.text = detail.loanTime
        tv_payback_money.text = detail.tenantRebate+"元"
    }

}
